mui.init();

mui.plusReady(function() {
	var header = plus.webview.currentWebview().chatHeader;
	var chatName = plus.webview.currentWebview().chatName;
	var roomId = plus.webview.currentWebview().roomId;
	var chatdata = chat.get(roomId);
	//console.log(JSON.stringify(chatdata));
	var dochead = document.querySelector('.header');
	var docname = document.querySelector('#name');
	//if(header.indexOf('upload') === -1) {
	//	header = "../../" + header;
	//}
	var header = app.avatar(roomId, '../../static/images/1.png');
	console.log(header);
	//document.querySelector('.header').setAttribute('src', header);
	dochead && dochead.setAttribute('src', header);
	if(docname) {
		docname.innerHTML = chatName;
	}
	
	
	var topmsgas = document.getElementById('topmsgas');
	
	if(topmsgas) {
		var classList = topmsgas.classList;

		if(chat.getval(roomId, 'istop')) {
			classList.add("mui-active");
		}
		
		topmsgas.addEventListener('tap', function() {
			chat.setval(roomId, 'istop', classList.contains('mui-active'));
		});
	}
	
	if(document.getElementById('clearmsg')) {
		document.getElementById('clearmsg').addEventListener('tap', function() {

			chat.removeChat(roomId);
			mui.toast('清除成功！');
			mui.fire(plus.webview.currentWebview().opener(), 'clear');
		});
	}
	
	if(document.getElementById('searchmsg')) {
		document.getElementById('searchmsg').addEventListener('tap', function() {
			mui.back();
		});
	}

	dochead && dochead.addEventListener('click', function() {
		mui.openWindow({
			url: '../user/other_detail.html',
			id: '../user/other_detail.html',

			show: {
				autoShow: true,
				aniShow: 'slide-in-right',
				duration: 100
			},
			waiting: {
				autoShow: true,
				title: 'waiting...'
			},
			extras: {
				chatHeader: header,
				chatName: chatName,
				fid: roomId
			}
		})
	});
	
	document.getElementById('jiaqun').addEventListener('tap',function(){
		mui.openWindow({url : '../../pages/chat/add_room.html', id : 'addroom'});
	});
})